﻿using System;
using System.Collections.Generic;

namespace Sinacor.Infra.Core.Licensing.Business
{
    public class Modulo
    {
        #region Attributes
        private Data.Modulo _resourceAccess;
        private object locker = new object();
        #endregion

        #region Constructor

        public Modulo()
        {
            _resourceAccess = new Data.Modulo();
        }

        #endregion

        #region Methods

        public List<Sinacor.Infra.Core.Licensing.Module> Selecionar(Sinacor.Infra.Core.Licensing.Module entity)
        {
            return _resourceAccess.Selecionar(entity);
        }
        public List<Sinacor.Infra.Core.Licensing.Module> Selecionar()
        {
            return _resourceAccess.Selecionar();
        }

        public void Incluir(Sinacor.Infra.Core.Licensing.Module library)
        {         
            library.ID = _resourceAccess.SelecionarProximoIdModulo();
            _resourceAccess.Incluir(library);         
        }

        public void Alterar(Sinacor.Infra.Core.Licensing.Module entity)
        {
            _resourceAccess.Alterar(entity);
        }

        public void Excluir(Sinacor.Infra.Core.Licensing.Module entity)
        {
            _resourceAccess.Excluir(entity);
        }

        private int SelecionarProximoIdModulo()
        {
            int nextId = 0;

            lock (locker)
            {
                nextId = _resourceAccess.SelecionarProximoIdModulo();
            }

            return nextId;
        }

        #endregion
    }
}
